#include <iostream>
#include <unistd.h>
#include <fstream>
#include <string>
#include <jsoncpp/json/json.h>

struct stu
{
    std::string name;
    int age;
    double wegiht;

public:
    void Print()
    {
        std::cout << name << std::endl;
        std::cout << age << std::endl;
        std::cout << wegiht << std::endl;
    }
};


int main()
{
    struct stu zs = {"张三", 24, 65};

    Json::Value root;
    root["name"] = zs.name;
    root["age"] = zs.age;
    root["wegiht"] = zs.wegiht;
    root["self"] = root;

    Json::FastWriter writer;
    std::string str = writer.write(root);
    
    std::ofstream out("out.txt");
    if(!out.is_open())
    {
        std::cout << str;
        return 1;
    }
    out << str;
    out.close();

    std::ifstream in("out.txt");
    if(!in.is_open()) return 1;
    char buffer[1024];
    in.read(buffer, sizeof(buffer));
    in.close();

    std::string json_string = buffer;
    Json::Value values;
    Json::Reader readr;
    bool res = readr.parse(json_string, values);
    (void)res;

    struct stu tmp;
    tmp.name = values["name"].asString();
    tmp.age = values["age"].asInt();
    tmp.wegiht = values["wegiht"].asDouble();
    tmp.Print();

    return 0;
}
